<template>
    <div>
        <el-button type="primary" @click="submitAnswer" class="submit-button">交卷并查看结果</el-button>
    </div>
</template>

<script>
    import * as api_module from "@/api/api";
    import {reactive} from 'vue'
    export default {
        name: "SubmitAnswerSheet",
        props:{
            subjects:{
                type:Array,
                default:[]
            },
            source:{
                type:Object,
                default:{}
            },
            active_idx:{
                type:Number,
                default:0
            },
            submitMethods:{
               type:String,
               default:''
            }
        },
        setup(props,{emit}){
            let submitAnswer = async () =>{
                console.log('提交数据',props.subjects);
                let answerLogs = [];
                for (let item of props.subjects){
                    if(item.user_answer){
                        let param = {};
                        param['id'] = item.id;
                        param['answer'] = item.user_answer.split('')
                        answerLogs.push(param);
                    }
                }
                let params = {
                    state:1,
                    id:props.source.id,
                    index:props.active_idx,
                    useTime:props.source.useTime,
                    answerLogs:answerLogs
                }
                let res = await api_module[props.submitMethods](params)
                console.log('提交成功',res)
                emit('sumbmitResult',res);
            }
            return{
                submitAnswer
            }
        }
    }
</script>

<style scoped>
.submit-button{
    width: 100%;
}
</style>
